from typing import Any

from sqlalchemy import insert, select, update, delete

from recruit.adapter.database.gateway.resume_base import BaseResumeGateway
from recruit.adapter.database.models import ResumeEducation
from recruit.adapter.stubs import StubResumeEducation
from recruit.domain.models.resume_id import ResumeId


class ResumeEducationGateway(BaseResumeGateway, StubResumeEducation):
    async def create(self, **kwargs: Any) -> ResumeEducation:
        stmt = insert(ResumeEducation).values(**kwargs).returning(
            ResumeEducation
        )
        return await super().create(stmt)

    async def get_one(self, **kwargs: Any) -> ResumeEducation | None:
        stmt = select(ResumeEducation).filter_by(**kwargs)
        return await super().get_one(stmt)

    async def update(
            self,
            resume_id: ResumeId,
            **kwargs: Any
    ) -> ResumeEducation:
        stmt = update(ResumeEducation).values(**kwargs).where(
            ResumeEducation.resume_id == resume_id
        ).returning(ResumeEducation)
        return await super().update(stmt)

    async def check_resume(self, resume_id: ResumeId) -> bool:
        stmt = select(ResumeEducation).where(
            ResumeEducation.resume_id == resume_id
        ).exists()
        return await super().check_resume(stmt)

    async def delete(self, resume_id: ResumeId) -> None:
        stmt = delete(ResumeEducation).where(
            ResumeEducation.resume_id == resume_id
        )
        await super().delete(stmt)
